import 'dart:convert';

class ProjectConfig {
  String projectPath;
  String projectName;
  String outputDir;
  String buildMode;
  String version;
  String companyName;
  String description;
  String iconPath;
  bool showConsole;
  bool enableOptimization;
  bool followImports;
  bool includeDataFiles;
  bool debugMode;

  ProjectConfig({
    this.projectPath = '',
    this.projectName = '',
    this.outputDir = '',
    this.buildMode = 'standalone',
    this.version = '1.0.0',
    this.companyName = '',
    this.description = '',
    this.iconPath = '',
    this.showConsole = false,
    this.enableOptimization = true,
    this.followImports = true,
    this.includeDataFiles = false,
    this.debugMode = false,
  });

  Map<String, dynamic> toJson() {
    return {
      'projectPath': projectPath,
      'projectName': projectName,
      'outputDir': outputDir,
      'buildMode': buildMode,
      'version': version,
      'companyName': companyName,
      'description': description,
      'iconPath': iconPath,
      'showConsole': showConsole,
      'enableOptimization': enableOptimization,
      'followImports': followImports,
      'includeDataFiles': includeDataFiles,
      'debugMode': debugMode,
    };
  }

  factory ProjectConfig.fromJson(Map<String, dynamic> json) {
    return ProjectConfig(
      projectPath: json['projectPath'] ?? '',
      projectName: json['projectName'] ?? '',
      outputDir: json['outputDir'] ?? '',
      buildMode: json['buildMode'] ?? 'standalone',
      version: json['version'] ?? '1.0.0',
      companyName: json['companyName'] ?? '',
      description: json['description'] ?? '',
      iconPath: json['iconPath'] ?? '',
      showConsole: json['showConsole'] ?? false,
      enableOptimization: json['enableOptimization'] ?? true,
      followImports: json['followImports'] ?? true,
      includeDataFiles: json['includeDataFiles'] ?? false,
      debugMode: json['debugMode'] ?? false,
    );
  }

  String toJsonString() {
    return jsonEncode(toJson());
  }

  factory ProjectConfig.fromJsonString(String jsonString) {
    return ProjectConfig.fromJson(jsonDecode(jsonString));
  }

  ProjectConfig copyWith({
    String? projectPath,
    String? projectName,
    String? outputDir,
    String? buildMode,
    String? version,
    String? companyName,
    String? description,
    String? iconPath,
    bool? showConsole,
    bool? enableOptimization,
    bool? followImports,
    bool? includeDataFiles,
    bool? debugMode,
  }) {
    return ProjectConfig(
      projectPath: projectPath ?? this.projectPath,
      projectName: projectName ?? this.projectName,
      outputDir: outputDir ?? this.outputDir,
      buildMode: buildMode ?? this.buildMode,
      version: version ?? this.version,
      companyName: companyName ?? this.companyName,
      description: description ?? this.description,
      iconPath: iconPath ?? this.iconPath,
      showConsole: showConsole ?? this.showConsole,
      enableOptimization: enableOptimization ?? this.enableOptimization,
      followImports: followImports ?? this.followImports,
      includeDataFiles: includeDataFiles ?? this.includeDataFiles,
      debugMode: debugMode ?? this.debugMode,
    );
  }
}